home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / comm / tcp / rxsocket.lha / rxsocket / examples / echomix.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1998-10-27  |  1.6 KB  |  61 lines

  1. /*
  2.   Mix protocol echo client.
  3.   Shows the usage of OpenConnection().
  4.   Just a simple echo client, but it wants as second argument
  5.   the string "TCP" or "UDP".
  6.   To try this on localhost be sure your echo/tcp and echo/udp
  7.   services are enabled in the inetd database.
  8.   Then just write
  9.   - rx echomix localhost tcp
  10.   - rx echomix localhost udp
  11. */
  12.  
  13. if ~show("L","rexxsupport.library") then
  14.     if ~addlib("rexxsupport.library",0,-30) then do
  15.         say "no rexxsupport.library"
  16.         exit
  17.     end
  18. if ~show("L","rxsocket.library") then
  19.     if ~addlib("rxsocket.library",0,-30) then do
  20.         say "no rxsocket.library"
  21.         exit
  22.     end
  23. if ~show("L","rmh.library") then
  24.     if ~addlib("rmh.library",0,-30) then do
  25.         say "no rmh.library"
  26.         exit
  27.     end
  28.  
  29. prg = ProgramName("NOEXT")
  30.  
  31. if ~RMH_ReadArgs("HOST/A,PROTO/A") then do
  32.     call PrintFault(IoErr(),prg)
  33.     exit
  34. end
  35. if parm.1.value~="tcp" & parm.1.value~="udp" then call err "PROTO must be 'tcp' or 'udp'"
  36.  
  37. sock=OpenConnection(parm.1.value,"echo",parm.0.value)
  38. if sock<0 then
  39.     select
  40.         when sock==-5 then call err "echomix: can't bind socket on port."
  41.         when sock==-4 then call err "echomix: service echo not found."
  42.         when sock==-3 then call err "echomix: service not found."
  43.         when sock==-2 then call err "echomix: host <" || parm.0.value || "> not found."
  44.         when sock==-1 then call "echomix: unable to connect <"parm.0.value":echo> (" || errno() || ")"
  45.     end
  46.  
  47. request="echo service test"
  48. if send(sock,request)~=length(REQUEST) then
  49.     call err "echomix: send error (" || errno() || ")"
  50.  
  51. len=recv(sock,"BUF",256)
  52. if len<0 then call err "echomix: recv error (" || errno() || ")"
  53.  
  54. say buf
  55. call CloseSocket(sock)
  56. exit
  57.  
  58. err:
  59. parse arg msg
  60.     say prg":" msg
  61.     exit